package com.cdivtc.management.service;

import com.cdivtc.management.dao.ClazzMapper;
import com.cdivtc.management.dao.CollageMapper;
import com.cdivtc.management.dao.MajorMapper;
import com.cdivtc.management.dao.StudentMapper;
import com.cdivtc.management.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    @Autowired
    private CollageMapper collageMapper;


    @Autowired
    private MajorMapper majorMapper;

    public Map<String, Object> stuInfoById(String stuId) {
        Student student = studentMapper.selectByPrimaryKey(stuId);
        String clazzId = student.getClazzId();
        Clazz clazz = clazzMapper.selectByPrimaryKey(clazzId);
        String majorname = clazz.getMajorname();
        Major major = majorMapper.selectByPrimaryKey(majorname);
        String college = student.getCollege();
        Collage collage = collageMapper.selectByPrimaryKey(college);
        Map<String, Object> map = new HashMap<>();
        map.put("student", student);
        map.put("majorName", major.getMajorname());
        map.put("colName", collage.getColname());
        map.put("className", clazz.getClazzName());
        //System.out.println("StudentService line 43= " + map);
        return map;
    }

    //根据老师所在学院查询学生信息
    public void selStuByTeaCollege(String college){
        Example example = new Example(Student.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("college", college);
        List<Student> students = studentMapper.selectByExample(example);
        for (Student student : students) {
            Map<String, Object> map = stuInfoById(student.getId());
            //System.out.println("StudentService line 56= " + map);
        }
    }

    public class StuInfo{

    }


}
